2 Copyright (C) 2024 Rubén Beltrán del Río
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
20 struct MapGroup: View {
23 let vertexSize: CGSize
27 let cornerSize = CGSize(width: 2.0, height: 2.0)
28 var strokeSize: CGFloat { 1.75 * vertexSize.width }
31 let groupList = group.map({ vertex in
32 return [Double(vertex.position.x), Double(vertex.position.y)]
35 let hullPoints = hull.hull(groupList, nil)
36 return hullPoints.compactMap({ object in
37 if let point = object as? [Double] {
38 return CGPoint(x: point[0], y: point[1])
46 var initialMove: CGPoint?
49 let offsetPoint = CGPoint(x: w(point.x), y: h(point.y))
51 if initialMove == nil {
52 path.move(to: offsetPoint)
53 initialMove = offsetPoint
55 path.addLine(to: offsetPoint)
59 if let initialMove = initialMove {
60 path.addLine(to: initialMove)
65 CGAffineTransform(translationX: vertexSize.width / 2.0, y: vertexSize.height / 2.0)
71 lineWidth: strokeSize,
81 func h(_ dimension: CGFloat) -> CGFloat {
82 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
85 func w(_ dimension: CGFloat) -> CGFloat {
86 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
92 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
94 Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)),
95 Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square),
96 Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle),
97 Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x),